package com.lm.tika.example;

import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.sax.BodyContentHandler;

import java.io.File;
import java.io.FileInputStream;

public class ImageMetadata {
    public static void main(String[] args) {
        try {
            File file = new File("E:\\hmtd-tool\\c7067c963527d63e5769f6438b4142d9.jpeg");
            FileInputStream inputStream = new FileInputStream(file);

            Metadata metadata = new Metadata();
            AutoDetectParser parser = new AutoDetectParser();
            parser.parse(inputStream, new BodyContentHandler(), metadata);

            System.out.println("📸图片元数据: ");
            for (String name : metadata.names()) {
                System.out.println(name + ": " + metadata.get(name));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
